﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using HtmlParser.Html;
using System.Net;
using GToolKit.IO;
using System.Collections;


namespace HtmlParserTest
{
    class Program
    {

        static void Main(string[] args)
        {
            var container = new CookieContainer();
            string baseUri = "http://www.163.com";
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(baseUri);
            request.Accept = "text/html, application/xhtml+xml, */*";
            request.UserAgent = "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)";
            request.Method = "GET";
            request.CookieContainer = container;
            request.BeginGetResponse(e =>
            {

                HttpWebRequest request1 = (HttpWebRequest)e.AsyncState;
                HttpWebResponse response = (HttpWebResponse)request1.EndGetResponse(e);
                var encoding = response.CharacterSet;
                StreamReader reader = new StreamReader(response.GetResponseStream(), System.Text.Encoding.GetEncoding(encoding));
                List<string> htmlList = new List<string>();
                string s = null;
                while ((s = reader.ReadLine()) != null)
                {
                    htmlList.Add(s);
                }
                //string html = reader.ReadToEnd();
                var hDoc = new HtmlDocumentEx();
                var list = hDoc.Parse(htmlList.ToArray());

             
                //DOMCore.HtmlParser parse = new DOMCore.HtmlParser();
                //List<DOMCore.TagInfo> objstream = parse.ParseHTML(reader);
                Console.WriteLine("OverHtml");

            }, request);

            //Stack<string> stack = new Stack<string>();
            //stack.Push("ddd");
            //stack.Push("dd1");
            //stack.Pop();
            //stack.Pop();
            //Console.WriteLine(stack.Peek());

            //WebClient webclient = new WebClient();
            //webclient.Encoding = System.Text.Encoding.GetEncoding("GB2312");
            ////string html = webclient.DownloadString("http://www.soku.com/search_video/q_%E5%86%9B%E6%83%85");//http://www.163.com

            //StreamReader reader = new StreamReader(CommonIO.GetFromResources(typeof(Program), "HtmlParserTest.p.html"));
            //string html = reader.ReadToEnd();
            //var hDoc = new HtmlDocumentEx();
            //var list = hDoc.Parse(html);
            Console.ReadKey();
        }
    }
}
